<template>
  <div class="heritage-list">
    <div class="list-header">
      <h1>文化遗产列表</h1>
      <el-input
        v-model="searchQuery"
        placeholder="搜索文化遗产..."
        prefix-icon="Search"
        clearable
        @input="handleSearch"
      />
    </div>
    
    <div class="list-content">
      <el-empty v-if="!filteredHeritage.length" description="暂无数据" />
      <div v-else class="heritage-grid">
        <heritage-card
          v-for="item in filteredHeritage"
          :key="item.id"
          :heritage="item"
          @click="viewDetail(item.id)"
        />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { useHeritageStore } from '@/stores/heritageStore'
import HeritageCard from '@/components/HeritageCard.vue'

const router = useRouter()
const heritageStore = useHeritageStore()
const searchQuery = ref('')

const filteredHeritage = computed(() => {
  if (!searchQuery.value) return heritageStore.heritageList
  const query = searchQuery.value.toLowerCase()
  return heritageStore.heritageList.filter(item => 
    item.name.toLowerCase().includes(query) ||
    item.description.toLowerCase().includes(query)
  )
})

const handleSearch = () => {
  // 可以添加防抖逻辑
}

const viewDetail = (id) => {
  router.push(`/heritage/${id}`)
}
</script>

<style scoped>
.heritage-list {
  padding: 20px;
}

.list-header {
  margin-bottom: 20px;
}

.list-header h1 {
  margin-bottom: 16px;
}

.heritage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}
</style> 